package com.hns.can.energy.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hns.can.base.entity.SysUserEntity;
import com.hns.can.common.web.BaseController;
import com.hns.can.energy.service.HomeEnergyService;

/**
 * 能耗首页controller
 * @author:zhangyu
 * @email:zhangyu2222z@sina.cn
 * @version Revision 2.0.0
 */
@Controller
@RequestMapping("/homeEnergy")
public class HomeEnergyController extends BaseController {
	@Autowired
	private HomeEnergyService homeEnergyService;	//能耗首页service
	
	/**
	 * 加载能耗首页数据通用方法
	 * @param funcType 功能类型
	 * @param dateType 日期类型
	 * @param lineId	线路id
	 * @param idxType 业务类型
	 * @param clazzName 转化类型字符串
	 * @return
	 * @throws Exception
	 * @author:zhangyu
	 * @email:zhangyu2222z@sina.cn
	 */
	@RequestMapping({"/getEnergyIndex","/getEnergyInfluence","/getEnergyTendencyChart","/getEnergyCarsRanking","/getEnergyExceptionRanking",
		"/getEnergyStatusRanking","/getEnergyCostTendency","/getEnergyStatusPieChart","/getEnergyCostRanking","/getEnerMultiInfo"})
	@ResponseBody
	public Object callMethod(String funcType, String dateType, String lineId, String idxType, String clazzName) throws Exception {
		Map<String, Object> map = formatParams(dateType, lineId, idxType);
		List<T> list = homeEnergyService.callMethod(funcType, map, clazzName);
		return this.getReturnResult(list);
	}
	
	/**
	 * 初始化参数
	 * @param dateType 日期类型
	 * @param lineId 线路id
	 * @param idxType 业务类型
	 * @return
	 * @author:zhangyu
	 * @email:zhangyu2222z@sina.cn
	 */
	private Map<String, Object> formatParams(String dateType, String lineId, String idxType){
		SysUserEntity user = this.getCurrentUser().getUser();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("dateType", dateType);
		map.put("lineId", lineId);
		map.put("idxType", idxType);
		map.put("corpId", user.getCorpId());
		map.put("userId", user.getId());
		return map;
	}
}
